package socdev.mobile;

import socdev.mobile.TasksJsonAdapter.TaskHolder;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class CommitsJsonAdapter extends ArrayAdapter<Commit>{

	Context context;
	int layoutResourceId;
	Commit [] data;
	public CommitsJsonAdapter(Context context, int textViewResourceId, Commit [] data) {
		super(context, textViewResourceId, data);
		this.context = context;
		this.layoutResourceId = textViewResourceId;
		this.data = data;
	}
	
	@Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        CommitHolder holder = null;
        
        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);
            
            holder = new CommitHolder();
            holder.message = (TextView)row.findViewById(R.id.message);
            holder.author = (TextView)row.findViewById(R.id.author);
            holder.date = (TextView)row.findViewById(R.id.date);
            
            row.setTag(holder);
        }
        else
        {
            holder = (CommitHolder)row.getTag();
        }
        
        Commit commit = data[position];
        holder.message.setText(commit.message);
        holder.author.setText(commit.author);
        holder.date.setText(commit.date);
        return row;
    }
	
	static class CommitHolder
    {
        TextView message;
        TextView author;
        TextView date;
    }
	
}
